﻿using System.Configuration;
using Service4u2.Json;
using System;

namespace HaloReachApi
{
    public class BaseReachApiJsonService<TResponse> : BaseJsonService<TResponse>
        where TResponse : new()
    {
        public const string APIKeyAppSettingName = "HaloReachAPIKey";

        protected string apiKey = string.Empty;
        
        public BaseReachApiJsonService()            
        {
            var key = string.Empty;
            AppSettings.TryGetSetting(APIKeyAppSettingName, out key);

            if (string.IsNullOrEmpty(key))
                throw new ArgumentNullException("APIKey", "Please specify an API Key; We look for a setting called " + APIKeyAppSettingName + " in IsolatedStorageSettings.");

            this.apiKey = key;
        }

        public BaseReachApiJsonService(string key)
        {
            if (string.IsNullOrEmpty(key))
                throw new ArgumentNullException("APIKey", "Please specify an API Key");

            this.apiKey = key;
        }
    }
}
